package cs.ubbcluj.ro.algorithm;

import cs.ubbcluj.ro.datatypes.interfaces.Vector;
import cs.ubbcluj.ro.lp.LP;

public class AlgorithmPrimalDualSqrt extends AlgorithmBase {

	public AlgorithmPrimalDualSqrt(LP lp, double sigma, double rho, double epsilon, double theta) {
		super(lp, sigma, rho, epsilon, theta);
	}
	
	/**
	 * calculates the value of 'nu' given by the formula: nu = 2 * (sqrt(mu * x * s) - x * s) 
	 * @return Vector
	 * @throws InterruptedException
	 */
	public Vector calculateRightHandSide() throws InterruptedException {
		// calculate the value of x * s and store it in a temporary array
		Vector xs = lp.getX().createHelperVector(lp.getXLength());
		xs.set(lp.getX());
		xs.productScalar(lp.getS());
		
		// calculate 2 * (sqrt(mu * x * s) - x * s)
		Vector resultVector = xs.createHelperVector(xs.getNrOfRows());
		resultVector.set(xs);
		resultVector.product(mu);		
		resultVector.sqrt();		
		resultVector.set(resultVector.diff(xs));		
		resultVector.product(2);
		
		return resultVector;
	}

}
